<?php include "../public/header.php";?>
<?php include "../public/header_edit.php";?>
<link rel="stylesheet" type="text/css" href="/static/component/laytp/module/cityPicker/city-picker.css">

<body id="optPage">
<form class="layui-form layui-form-pane" id="commentForm">
    <div class="page-title"><div class="page-title-con"><span>收款截息</span><div class="move_title"></div><?php include "../public/sub.php";?></div></div>
    <div class="main-container">
        <div class="block-generic">
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>基本信息</span></div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">项目名称</label>
                        <div class="layui-input-block">
                            <input type="hidden" id="enginid">
                            <input type="text" id="enginid_name" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>关联项目收款</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="incenid" class="layui-input incenid" onclick="choose_income_engin()">
                            <div class="choose_div" id="incenid" key="1"></div>
                            <span class="choose_one" onclick="choose_income_engin()"><i class="layui-icon layui-icon-search"></i></span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">到账日期</label>
                        <div class="layui-input-block">
                            <input type="text" id="dt" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                </div>
            </div>
        </div>

    </div>
</form>
<script>
    var param_id = getQueryVariable('id') || 0;


    function choose_income_engin(){
        var enginid = $("#enginid").val();
        if(!enginid){
            facade.error("没有关联项目信息，无法操作关联项目收款");return false;
        }
        openPage('../public/choose_income_engin.php?dom=incenid&page=piao_kai_jiexi&enginid='+enginid,'80%','80%')
    }

    layui.use(['laytp', 'form'], function() {
        var form = layui.form, layer = layui.layer;
        render_input_attr();

        facade.ajax({type: 'get', url: ask_piao_kai_jiexi,data:{id:param_id}}).done(function(res){
            if (res.code === 2000) {
                var data = res.data.data;

                var engininfo = res.data.engininfo;
                if(engininfo){
                    $("#enginid").val(engininfo.id);
                    $("#enginid_name").val(engininfo.name);
                }

                var incenidinfo = res.data.incenidinfo;
                if(incenidinfo){
                    set_choose_btn('incenid',incenidinfo.id,incenidinfo.sericnum);
                    $("#dt").val(incenidinfo.dt);
                }

                render_from();
            }
        });

        form.on('submit(add)', function(data){
            var validRes = $("#commentForm").valid();

            data.field.incenid = get_choose_val('incenid');
            formValid('incenid');
            if(data.field.incenid == undefined || !data.field.incenid){
                validRes = false;
            }

            if(!validRes){return false;}


            data = parseMoney(data);
            data.field.id = param_id;
            facade.ajax({url: ask_piao_kai_jiexi, data:data.field}).done(function(res){
                if (res.code === 2000) {
                    dataPostTimeOut();
                }
            });

            return false;
        });

    });

</script>
</body>
</html>
